from qtcommon import tr
from ordereddict import OrderedDict

class DicList(list):
    def __init__(self, *args):
        list.__init__(self)
        for i in args:
            self.append(i)
    def __getitem__(self,n):
        for u,v in self:
            if u==n :
                return v
            
        raise KeyError
    
class AttrDict(OrderedDict):
    def __init__(self, *args, **kwargs):
        OrderedDict.__init__(self, *args, **kwargs)
    def __getattr__(self, name):
        if name.startswith('_'):
            return self.__getattribute__(name)
        else:
            self[name]

    def __setattr__(self, name ,value):
        if name.startswith('_'):
            self.__dict__[name]=value
        else:
            self[name] = value

class OrderedTastingAtt_t(object):
    # OrderedTastingAtt = DicList{
    visual = DicList( ('visual_color' , tr("Color") ),    
                       ('visual_viscosity' , tr("Viscosity") ),
                       ('visual_shine' , tr("Shine") ),
                       ('visual_more' , tr("Others") ),
                       )
    visual_desc = tr("Visual aspects")
    
    smell  =  DicList( ('smell_first' , tr("First smell") ),
                        ('smell_strength' , tr("Strength") ),
                        ('smell_aroma' , tr("Aromas") ),
                        ('smell_more' , tr("Others") ),
                       )
    smell_desc = tr("Smelling aspects")


    taste = DicList( ('taste_start' , tr('Start') ),
                      ('taste_balance' , tr('Balance') ),
                      ('taste_body' , tr('Body') ),
                      ('taste_final' , tr('Final') ),
                      ('taste_length' , tr('Lenght') ),
                      ('taste_more' , tr('Others') ),
                      )
    taste_desc = tr("Tasting aspects")


    comment = tr("Other Comments")

    def iterattributes(self):
        for a in ['visual', 'smell','taste']:
            yield a, self[a]
    def iterAll(self):
        for ag, d in self.iterattributes():
            for a,ad in d:
                yield a,ad
            yield ag,getattr(self,ag+'_desc')
        yield 'comment', self.comment

    def __getitem__(self,n):
        return getattr(self,n)

OrderedTastingAtt = OrderedTastingAtt_t()    
def allTastingAtt():
    for t, d in OrderedTastingAtt.iteritems():
        for k,v in d.iteritems():
            yield k,v

## TastingText = DicList(
##     visual_color     , tr("Color") ),
##     visual_viscosity , tr("Viscosity") ),
##     visual_shine     , tr("Shine") ),
##     visual_more      , tr("Visual aspects") ),

##     smell_first     , tr("First smell") ),
##     smell_strength  , tr("Strength") ),
##     smell_aroma     , tr("Aromas") ),
##     smell_more      , tr("Smell") ),

##     taste_start   , tr('Start') ),
##     taste_balance , tr('Balance') ),
##     taste_body    , tr('Body') ),
##     taste_final   , tr('Final') ),
##     taste_length  , tr('Lenght') ),
##     taste_more    , tr('Taste') ),


##     )

